home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 5.9 KB | 234 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UInsertPartCommand.cp
- // Copyright © 1994-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __UINSERTPARTCOMMAND__
- #include "UInsertPartCommand.h"
- #endif
-
- #if qContainer
-
- #ifndef __UODPARTVIEW__
- #include "UODPartView.h"
- #endif
-
- // MacApp
-
- #ifndef __UCLIPBOARDMGR__
- #include "UClipboardMgr.h"
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __UMEMORY__
- #include "UMemory.h"
- #endif
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
- // CALib
-
- #if qContainer
- #ifndef _CALIB_
- #include "CALib.h"
- #endif
- #endif
-
- // Toolbox
-
- #ifndef __STANDARDFILE__
- #include <StandardFile.h>
- #endif
-
- #ifndef __STDLIB__
- #include <stdlib.h>
- #endif
-
- //========================================================================================
- // CLASS TInsertPartCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TCommand
-
- #pragma segment ASelCommand
- MA_DEFINE_CLASS_M1(TInsertPartCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // Constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- TInsertPartCommand::TInsertPartCommand()
- : fODPartView(NULL),
- fDocument(NULL)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // Destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TInsertPartCommand::~TInsertPartCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TInsertPartCommand::IInsertPartCommand
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- Boolean TInsertPartCommand::IInsertPartCommand(CommandNumber itsCommandNumber,
- TDocument* itsDocument,
- TODPartView* itsPartView)
- {
- Boolean fileChosen = ChoosePartFile();
- if (fileChosen)
- {
- this->ICommand(itsCommandNumber, itsDocument,
- kCanUndo, kCausesChange, itsDocument);
- fDocument = itsDocument;
- fODPartView = itsPartView;
- }
-
- return fileChosen;
- }
-
- //----------------------------------------------------------------------------------------
- // TInsertPartCommand::DoIt()
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TInsertPartCommand::DoIt()
- {
-
- if (fODPartView)
- {
-
- //Remove the old part.
- if(fODPartView->HasPart())
- {
- fODPartView->RemovePart();
- }
-
- // IF THERE IS NO fODPartView, make one. for now, upper left? •••
- //if(!fODPartView)
- //fODPartView = new
-
- fODPartView->AquirePartFromFile(fFileSpec);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TInsertPartCommand::UndoIt()
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TInsertPartCommand::UndoIt()
- {
- if(fODPartView->HasPart())
- {
- fODPartView->RemovePart();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TInsertPartCommand::RedoIt()
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TInsertPartCommand::RedoIt()
- {
- this->DoIt();
- }
-
- //----------------------------------------------------------------------------------------
- // TInsertPartCommand::ChoosePartFile
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- Boolean TInsertPartCommand::ChoosePartFile()
- {
- FailOSErr(MAInteractWithUser());
- gClipboardMgr->AboutToLoseControl(TRUE); // so scrap gets converted
-
- Boolean done = FALSE;
-
- // Insure we can go modal at this time.
- WindowPtr frontWindow = CAGetFrontDocWindow();
- if (CARequestModalFocus(frontWindow))
- {
- StandardFileReply customReply;
- FileFilterYDUPP cgfFileFilter = NewFileFilterYDProc(TInsertPartCommand::PartFileFilter);
- ModalFilterYDUPP cgfModalFilter = NewModalFilterYDProc(gModalFilterYDProcPtr);
-
- CustomGetFile(cgfFileFilter,
- -1, // Pass all file types
- NULL, // No type list
- &customReply,
- sfGetDialogID,
- kBestSystemLocation,
- NULL, // Dialog hook function
- cgfModalFilter,
- NULL, // Activate list
- NULL, // Activate proc
- NULL);
-
- CARelinquishModalFocus(frontWindow);
-
- if (customReply.sfGood)
- {
- fFileSpec = customReply.sfFile;
- done = TRUE;
- }
- }
- return done;
- }
-
- //----------------------------------------------------------------------------------------
- // TInsertPartCommand::PartFileFilter
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- pascal Boolean TInsertPartCommand::PartFileFilter(CInfoPBPtr pb)
- {
- HFileInfo* fpb = (HFileInfo*)pb;
-
- if (!(fpb->ioFlAttrib & 16))
- {
- return (!(fpb->ioFlFndrInfo.fdCreator == kODShellSignature) &&
- (fpb->ioFlFndrInfo.fdType != 'APPL') &&
- (fpb->ioFlFndrInfo.fdType != 'shlb'));
- }
- return false;
- }
-
- //----------------------------------------------------------------------------------------
- // TInsertPartCommand::Commit
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TInsertPartCommand::Commit()
- {
- if (!fCommandDone && fODPartView)
- {
- fODPartView = (TODPartView*)FreeIfObject(fODPartView);
- }
- }
-
- #endif // qContainer
-
- //----------------------------------------------------------------------------------------
- // End of UInsertPartCommand.cp
-
- #pragma segment Inline
-